﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SLIP.Core;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.Logging;
using Microsoft.Practices.Prism.Events;

namespace ExampleModules.ViewModels
{
    public class ExampleViewModel2 : SLIPViewModelBase, IExampleViewModel2
    {
        private string _stringData;
        public string StringData
        {
            get
            {
                return _stringData;
            }
            set
            {
                _stringData = value;
                RaisePropertyChanged("StringData");
            }
        }

        public ExampleViewModel2(IRegionManager pManager, ILoggerFacade pLogger, IEventAggregator pAggregator)
            : base(pManager, pLogger, pAggregator) 
        {
            //Next two lines show Test Event example
            //var anEvent = _aggregator.GetEvent<TestEvent>();
            //anEvent.Subscribe(EventReceived);

            //Next lines show SLIPBaseEvent example
            SLIPBaseEvent anEvent = _aggregator.GetEvent<SLIPBaseEvent>();
            anEvent.Subscribe(SLIPBaseEventReceived);

            StringData = "Initialized...";
        }

        public void EventReceived(bool pVal)
        {
            StringData = "Event Received: " + DateTime.Now;
        }

        public void SLIPBaseEventReceived(BaseEvent pEvent)
        {
            if (pEvent != null)
            {
                //test if this is the Key we are waiting for
                if (pEvent.Key.Equals("TEST"))
                {
                    StringData = pEvent.Data.ToString();
                }
                else
                {
                    StringData = "Incorrect Event Received";
                }

            }
        }
    }
}
